<template>
  <div class="common-layout">
    <el-container>
      <!-- 头部 -->
      <el-header class="header">
        <el-menu
          class="el-menu-demo"
          mode="horizontal"
          background-color="#545c64"
          text-color="#fff"
          active-text-color="#ffd04b"
          router
          :default-active="activeIndex"
        >
          <el-menu-item index="/home">首页</el-menu-item>
          <el-menu-item index="/jishi">计时</el-menu-item>
        </el-menu>
      </el-header>
      <el-container>
        <!-- 内容 -->
        <el-main class="main">
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script setup lang="ts">
import { computed } from 'vue'
import { useRoute } from 'vue-router'

const route = useRoute()
const activeIndex = computed(() => {
  // 获取当前路径
  const path = route.path
  // 如果路径以 /home 开头，返回 /home
  if (path.startsWith('/Home/')) {
    return '/home'
  }
  // 如果路径以 /jishi 开头，返回 /jishi
  if (path.startsWith('/JiShi/')) {
    return '/jishi'
  }
  // 默认返回当前路径
  return path
})
</script>

<style scoped>
.header {
  padding: 0;
}
.main {
  padding: 0;
}
</style>
